package com.yimi.yinhepda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yimi.yinhepda.R;
import com.yimi.yinhepda.db.table.ScanDetailVo;

import java.util.List;

/**
 * @author gyy
 * @date 2017/9/12
 */

public class OffLineScanAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private List<ScanDetailVo> dataList;
    private Context context;

    public OffLineScanAdapter(Context context, List<ScanDetailVo> dataList) {
        this.context = context;
        this.dataList = dataList;
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return null != dataList ? dataList.size() : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ScanDetailVo item = dataList.get(position);
        OffLineScanAdapter.ViewHolder holder = null;
        if (convertView == null) {
            holder = new OffLineScanAdapter.ViewHolder();
            convertView = inflater.inflate(R.layout.offline_scan_item, null);
            // 运单号
            holder.waybillnum = convertView.findViewById(R.id.text1);
            //件数
            holder.count = convertView.findViewById(R.id.text3);
            // 时间
            holder.time = convertView.findViewById(R.id.text4);
            convertView.setTag(holder);
        } else {
            holder = (OffLineScanAdapter.ViewHolder) convertView.getTag();
        }
        // 运单号
        holder.waybillnum.setText(item.getWaybillNo());
        //开单数
        holder.count.setText(item.getQuantity() + "");
        // 时间
        holder.time.setText(item.getScanTime() + "");
        convertView.setBackgroundColor(context.getResources().getColor(R.color.red));

        return convertView;
    }

    static class ViewHolder {
        /**
         * 运单号
         */
        TextView waybillnum;
        /**
         * 件数
         */
        TextView count;
        /**
         * 时间
         */
        TextView time;
    }

    @Override
    public Object getItem(int position) {
        // TODO 自动生成的方法存根
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO 自动生成的方法存根
        return position;
    }

    public void setDataList(List<ScanDetailVo> scanList) {
        this.dataList = scanList;
    }
}
